<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:hlp="http://tecnologie-web.studenti.math.unipd.it/tecweb/~ccardin/"
    exclude-result-prefixes="hlp">
        
<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes' omit-xml-declaration='yes'/>    
    <!--Variabile per selezionare una determinata pagina-->

    <xsl:variable name="idPage" select="__PAGEID__"/>
    
    <xsl:template match="/">
	    <div id="searchbar">
			<form method="post" action="helpsearch.cgi">
				<div>
					<label for="query">Search:</label>
					<input type="text" id="query" name="query"/>
					<input type="submit" value="Search"/>
				</div>
			</form>
		</div>
<div id="content-title">
                <h2>
                    <span>SAKE HELP</span>
                    Learn how to use SAKE, or find resolution to your problems.
                </h2>
            </div>
		
	    <a class="hidden" href="#help-content">Go to help content</a>
	    <xsl:apply-templates select="hlp:help"/>
		
	    <div id="help-content">
			<xsl:choose>
				    <xsl:when test="count(hlp:help/hlp:category/hlp:helpPage[hlp:id=$idPage])=1">
						<xsl:apply-templates select="hlp:help/hlp:category/hlp:helpPage[hlp:id=$idPage]"/>
				    </xsl:when>
				    <xsl:otherwise>
						<p>Choose a page from the menu.</p>
				    </xsl:otherwise>
			</xsl:choose>
			
	    </div>
    </xsl:template>
    
    <xsl:template match="hlp:help">
		
		<xsl:for-each select="hlp:category">
			<ul class="list-help">
			<li><h3><xsl:value-of select="hlp:name"/></h3>
			<ul>
				<xsl:for-each select="hlp:helpPage">
					<xsl:if test="hlp:id=$idPage">
						<li><xsl:value-of select="hlp:title"/></li>
					</xsl:if>
					
					<xsl:if test="hlp:id!=$idPage">
						<li><a href="help.cgi?idPage={hlp:id}"><xsl:value-of select="hlp:title"/></a></li>
					</xsl:if>
					
				</xsl:for-each>
			</ul>
			</li>
			</ul>
		</xsl:for-each>
		
    </xsl:template>
    
    <xsl:template match="hlp:helpPage">
        
            <xsl:apply-templates select="hlp:title"/>
            <xsl:apply-templates select="hlp:content"/>
			<p class="to-top">
				<a href="#content">Return to top</a><br/>
				<a class="to-menu" href="#nav">Return to menu</a>
			</p>
    </xsl:template>
    
    <xsl:template match="hlp:title">
            <h2>
                <xsl:value-of select="." />
            </h2>
    </xsl:template>
    
    <xsl:template match="hlp:content">
            <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="hlp:content//hlp:subtitle">
        <h3>
            <xsl:value-of select="." />
        </h3>
    </xsl:template>
    
    <xsl:template match="hlp:content//hlp:helpImage">
        <p><img src="{hlp:path}" class="auralNotRead" alt="{hlp:imgDescription}" height="{@imgHeight}" width="{@imgWidth}" /></p>
    </xsl:template>
    
    <xsl:template match="hlp:content//hlp:helpLink">
        <a href="{hlp:to}" title="{hlp:title}" target="_blank"><xsl:value-of select="hlp:text"/></a>
    </xsl:template>
    
    <xsl:template match="hlp:content//text()">
        <xsl:copy-of select="." />
    </xsl:template>
  
</xsl:stylesheet>
